export const powerMapper = [
  {
    enum: [ 0, 0 ],
    key: 'lock_free',
    label: '无',
    color: 'purple',
  },
  {
    enum: [ 0, 700 ],
    key: 'lock_free',
    label: '电量无',
    color: 'red',
  },
  {
    enum: [ 700, 720 ],
    key: 'lock_free',
    label: '马上更换',
    color: 'red',
  },
  {
    enum: [ 720, 750 ],
    key: 'lock_occupied',
    label: '建议更换',
    color: 'orange',
  },
  {
    enum: [ 750, 900 ],
    key: 'lock_occupied',
    label: '正常',
    color: 'green',
  },
];

export const PowerParser = {
  parse: (num: number) => {
    if (!num) {
      const obj = powerMapper[0];
      return { ...obj, val: 0, label: '未知' };
    }
    const obj =
      powerMapper.find(item => item.enum?.[0] < num && item.enum?.[1] > num) ||
      powerMapper[powerMapper.length - 1];
    return { ...obj, val: num };
  },
  parseValue: (num: number) => {
    if (num === undefined) {
      const obj = powerMapper[0];
      return { ...obj, val: 0, label: '未知' };
    }
    const obj =
      powerMapper.find(item => item.enum?.[0] <= num && item.enum?.[1] > num) ||
      powerMapper[powerMapper.length - 1];
    const label = `${ obj.label }(${ num })`;
    return { ...obj, val: num, label };
  },
};
